#include "stdafx.h"
#include "lock.h"


//
// CCriticalSectionX
//
CCriticalSectionX::CCriticalSectionX()
{
	::InitializeCriticalSection(&m_cs);
}

CCriticalSectionX::~CCriticalSectionX()
{
	::DeleteCriticalSection(&m_cs);
}


void CCriticalSectionX::EnterCriticalSection()
{
	::EnterCriticalSection(&m_cs);
}

void CCriticalSectionX::LeaveCriticalSection()
{
	::LeaveCriticalSection(&m_cs);
}


//
// Lock
//
CLock::CLock(CCriticalSectionX& cs)
{
	m_pcs = &cs;
	Lock();
}

CLock::~CLock()
{
	Unlock();
}

void CLock::Lock()
{
	if (m_pcs)
	{
		m_pcs->EnterCriticalSection();
	}
}

void CLock::Unlock()
{
	if (m_pcs)
	{
		m_pcs->LeaveCriticalSection();
	}
}

